<?php

namespace app\admin\controller;


use app\admin\model\Plan;
use cmf\controller\AdminBaseController;
use think\facade\Db;

/**
 * Class PlanController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   =>'计划管理',
 *     'action' =>'index',
 *     'parent' =>'',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   =>'',
 *     'remark' =>''
 * )
 */
class PlanController extends AdminBaseController
{
    public
    function platesaddPost()
    {
        $post_data = $this->request->param();
//        var_dump($post_data);
//        exit();
        $plan_id = $post_data['plan_id'];
        $data = array();
        Db::startTrans();
        $list = 0;
//        var_dump($post_data);
//        exit();
        // 移除所有等同于FALSE的值
        $post_data['post'] = array_filter($post_data['post']);

// 自定义回调函数来过滤空字符串和null值
        $post_data['post'] = array_filter($post_data['post'], function ($value) {
            return ($value !== null && $value !== '');
        });
        foreach ($post_data['post'] as $k => $v) {
            if (isset($v['id'])){
                unset($v['id']);
            }
            if (isset($v['$isEdit'])){
                unset($v['$isEdit']);
            }
//            unset($v['$isEdit']);
            $d = Db::name('plate')->where($v)->find();

            $v['coil_id'] = $post_data['row'];
//            unset($v['coil_id']);
            $v['add_time'] = time();
            $v['update_time'] = time();
//            if (isset($v['weight'])){
//                $v['weight']=$v['weight']*1000;
//            }
            $v['admin_id'] = cmf_get_current_admin_id();

//            ->update(array('delete_time' => time(),'admin_id'=>cmf_get_current_admin_id()));

//            $data[$k] = $v;
            if (!$d) {
                array_push($data, $v);
                $list = Db::name('plate')->insert($v);
            }
        }
//        var_dump($post_data);
//        exit();
//        if (!$params) {
//            $this->error('非法参数');
//        }
//        $params['add_time'] = time();
//        var_dump($params);
//        Plate::create($params);
//        var_dump($data);


//        var_dump($data);
//        var_dump(Db::name('plate')->getLastSql());

        if ($list) {

//            foreach ($post_data['post'] as $k => $v) {
//var_dump($v['weight']);exit();
            $coil = Db::name('coil')->where('id', $post_data['row'])->find();

            if ($post_data['weight'] == '') {
                Db::rollback();
                $this->error('未填写钢卷剩余数量');
            }
            if ($coil['weight'] < $post_data['weight']) {
                $this->error('剩余数量不得大于现有数量');
                Db::rollback();
            }
            if (!isset($post_data['kuwei'])){
                $post_data['kuwei']='';
            }
            if ($post_data['weight'] == 0) {
                Db::name('coil')->where('id', $post_data['row'])->update(array('update_time' => time(), 'weight' => $post_data['weight'], 'locator' => $post_data['kuwei'], 'delete_time' => time(), 'admin_id' => cmf_get_current_admin_id()));
            } else {
                Db::name('coil')->where('id', $post_data['row'])->update(array('update_time' => time(), 'weight' => $post_data['weight'], 'locator' => $post_data['kuwei'], 'admin_id' => cmf_get_current_admin_id()));
            }

//            }
//            Db::name('plan')->where('id', $plan_id)->update(array('update_time' => time(), 'status' => 3, 'admin_id' => cmf_get_current_admin_id()));
            Db::commit();
            $this->success('操作成功', 'plan/allindex');
        } else {
            $this->error('操作失败');
        }
//
//        $this->success('操作成功', 'index');
    }

    public function getplan()
    {
        $id = $this->request->param("id");
        if (!$id) {
            $this->error('缺少参数');
        }
        $arr = array();
        $data = Db::name('plan')
            ->where('id', $id)
            ->where('delete_time', 0)
            ->order('add_time desc')
            ->find();
        // 移除所有等同于FALSE的值
        $data = array_filter($data);

// 自定义回调函数来过滤空字符串和null值
        $data = array_filter($data, function ($value) {
            return ($value !== null && $value !== '');
        });
        if ($data['pd'] > 0) {
            $data['pd'] = $data['pd'] * 1000;
        } else {
            $data['pd'] = '';
        }
        if ($data['delivery_time'] > 0) {
            $data['delivery_time'] = $data['delivery_time'] * 1000;
        } else {
            $data['delivery_time'] = '';
        }
        $data['coil_id'] = explode(",", $data['coil_id']);
//        $info['plate_id'] = explode(',', $info['plate_id']);
        foreach ( $data['coil_id'] as $k => $v) {
//            var_dump($v);
            $platearray[$v] = Db::name('coil')->where('id', $v)->find();
//            var_dump($platearray);
            if ( $platearray[$v]['delete_time']>0){
//                var_dump(1111);
//                var_dump($info['plate_id']);
//                var_dump($info['plate_id'][$k]);
                unset( $data['coil_id'][$k]);
//                var_dump($info['plate_id']);
            }
//            if ()
        }
        $arr['formData'] = $data;
        $proplan = Db::name('preplate')
            ->where('plan_id', $id)
            ->where('delete_time', 0)
            ->select();
        $pro = array();
        foreach ($proplan as $key => $val) {
            if (isset($val['weight'])){
                $val['weight']=$val['weight']/1000;
            }
            $val = array_filter($val);

// 自定义回调函数来过滤空字符串和null值
            $pro[$key] = array_filter($val, function ($value) {
                return ($value !== null && $value !== '');
            });
        }


        $arr['plan'] = $pro;

        $this->success("成功", '', $arr);
    }

    public function selctid()
    {
        $id = input('get.id/d');
        $coil_id_arr = Db::query('select * from cmf_coil where delete_time =0 and  id =' . $id);
        $this->success('ok', '', $coil_id_arr);
    }

    /**
     * @adminMenu(
     *     'name'   => '已完成',
     *     'parent' => 'index',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '已完成',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function endindex()
    {
        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->where('type', 1);
        $lists = $lists->where('status', 3);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);

        $company_id_arr = Db::name('company')
            ->column('name', 'id');
        $this->assign('company_id_arr', $company_id_arr);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);
        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');
        $this->assign('ht_id_arr', $ht_id_arr);
        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');
        $this->assign('grade_id_arr', $grade_id_arr);
        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);
        $coil_id_arr = Db::name('coil')
            ->column('name', 'id');
        $this->assign('coil_id_arr', $coil_id_arr);
        $type_id_arr = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $this->assign('type_id_arr', $type_id_arr);
        $c_type_arr = array(1 => '内贸', 2 => '调试', 3 => '委外加工', 4 => '外贸');

        $this->assign('c_type_arr', $c_type_arr);
//        $list = $lists->toArray();
//        $list['coil_id']=explode(',',  $list['coil_id']);
        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '进行中',
     *     'parent' => 'index',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '进行中',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function runindex()
    {
        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->where('type', 1);
        $lists = $lists->where('status', 2);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);

        $company_id_arr = Db::name('company')
            ->column('name', 'id');
        $this->assign('company_id_arr', $company_id_arr);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);
        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');
        $this->assign('ht_id_arr', $ht_id_arr);
        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');
        $this->assign('grade_id_arr', $grade_id_arr);
        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);
        $coil_id_arr = Db::name('coil')
            ->column('name', 'id');
        $this->assign('coil_id_arr', $coil_id_arr);
        $type_id_arr = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $this->assign('type_id_arr', $type_id_arr);
        $c_type_arr = array(1 => '内贸', 2 => '调试', 3 => '委外加工', 4 => '外贸');
        $this->assign('c_type_arr', $c_type_arr);
//        $list = $lists->toArray();
//        $list['coil_id']=explode(',',  $list['coil_id']);
        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '已下发',
     *     'parent' => 'index',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '已下发',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function xiafaindex()
    {
        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->where('type', 1);
        $lists = $lists->where('status', 1);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);

        $company_id_arr = Db::name('company')
            ->column('name', 'id');
        $this->assign('company_id_arr', $company_id_arr);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);
        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');
        $this->assign('ht_id_arr', $ht_id_arr);
        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');
        $this->assign('grade_id_arr', $grade_id_arr);
        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);
        $coil_id_arr = Db::name('coil')
            ->column('name', 'id');
        $this->assign('coil_id_arr', $coil_id_arr);
        $type_id_arr = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $this->assign('type_id_arr', $type_id_arr);
        $c_type_arr = array(1 => '内贸', 2 => '调试', 3 => '委外加工', 4 => '外贸');
        $this->assign('c_type_arr', $c_type_arr);
//        $list = $lists->toArray();
//        $list['coil_id']=explode(',',  $list['coil_id']);
        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '总列表',
     *     'parent' => 'index',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '总列表',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function allindex()
    {
        //搜索部分
//        $key_status = input('get.key_status/d');

        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->where('type', 1);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);

        $company_id_arr = Db::name('company')
            ->column('name', 'id');
        $this->assign('company_id_arr', $company_id_arr);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);
        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');
        $this->assign('ht_id_arr', $ht_id_arr);
        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');
        $this->assign('grade_id_arr', $grade_id_arr);
        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);
        $coil_id_arr = Db::name('coil')
            ->column('name', 'id');
        $this->assign('coil_id_arr', $coil_id_arr);
        $type_id_arr = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $c_type_arr = array(1 => '内贸', 2 => '调试', 3 => '委外加工', 4 => '外贸');
        $this->assign('c_type_arr', $c_type_arr);
        $this->assign('type_id_arr', $type_id_arr);
//        $list = $lists->toArray();
//        $list['coil_id']=explode(',',  $list['coil_id']);
        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }

    public function index()
    {
        //搜索部分
//        $key_status = input('get.key_status/d');

        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->where('type', 1);
        $lists = $lists->paginate(['list_rows' => 100, 'query' => [
            //'key_status' => $key_status
        ]]);

        $company_id_arr = Db::name('company')
            ->column('name', 'id');
        $this->assign('company_id_arr', $company_id_arr);
        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');

        $this->assign('user_arr', $user_arr);
        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');
        $this->assign('ht_id_arr', $ht_id_arr);
        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');
        $this->assign('grade_id_arr', $grade_id_arr);
        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $this->assign('companytypea_arr', $companytypea_arr);
        $coil_id_arr = Db::name('coil')
            ->column('name', 'id');
        $this->assign('coil_id_arr', $coil_id_arr);
        $type_id_arr = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $this->assign('type_id_arr', $type_id_arr);
        $c_type_arr = array(1 => '内贸', 2 => '调试', 3 => '委外加工', 4 => '外贸');
        $this->assign('c_type_arr', $c_type_arr);
//        $list = $lists->toArray();
//        $list['coil_id']=explode(',',  $list['coil_id']);
        return $this->fetch('', ['lists' => $lists->toArray(), 'page' => $lists->render(), 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * addvue
     */
    public function addvue()
    {
        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '新增开平计划新',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '新增',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function addnew()
    {
        $company_id_arr = Db::query('select id,name,abb_name from cmf_company where delete_time =0');
//        var_dump($company_id_arr);
        $this->assign('company_id_arr', $company_id_arr);
        $this->assign('company_id_arr1', json_encode($company_id_arr));
        $today = date('ymd', time());
        $name = '';
//        $this->success('ok', '',$today);
        $newnum = Db::name('plan_num')->where('today', $today)->order('id desc')->find();
        if ($newnum) {
            Db::name('plan_num')->insertGetId(array('today' => $today, 'order_num' => $newnum['order_num'] + 1, 'addtime' => time(),
                'admin_id' => cmf_get_current_admin_id()));
            $dd = str_pad($newnum['order_num'] + 1, 5, '0', STR_PAD_LEFT);
            $name = 'K' . $today . $dd;

        } else {
            Db::name('plan_num')->insertGetId(array('today' => $today, 'order_num' => 1, 'addtime' => time(),
                'admin_id' => cmf_get_current_admin_id()));
            $dd = str_pad(1, 5, '0', STR_PAD_LEFT);

            $name = 'K' . $today . $dd;
        }
        $this->assign('name', $name);
        $now_time = date('Y-m-d H:i', time());
        $this->assign('now_time', $now_time);
        $type_id_arr = array(
            0 => array('id' => 1, 'name' => '开平'),
            1 => array('id' => 2, 'name' => '切割'),
            2 => array('id' => 3, 'name' => '热处理'),
            3 => array('id' => 4, 'name' => '后处理'),
        );
        $c_type_arr = array(
            0 => array('id' => 1, 'name' => '内贸'),
            1 => array('id' => 2, 'name' => '调试'),
            2 => array('id' => 3, 'name' => '委外加工'),
            3 => array('id' => 4, 'name' => '外贸'),
        );
        $this->assign('c_type_arr', $c_type_arr);
        $this->assign('type_id_arr', $type_id_arr);
        $companytypea_arr = array(0 => array('id' => 1, 'name' => '自主'), 1 => array('id' => 2, 'name' => '来料'), 2 => array('id' => 3, 'name' => '委外'));
        $this->assign('companytypea_arr', $companytypea_arr);

        $steel_grade_id_arr = Db::query('select id,name from cmf_steel_grade where delete_time =0');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $grade_id_arr = Db::query('select id,g_name from cmf_grade where delete_time =0');
        $this->assign('grade_id_arr', $grade_id_arr);
        $this->assign('grade_id_arr1', json_encode($grade_id_arr));
        $coil_id_arr = Db::query('select * from cmf_coil where delete_time =0');
//        var_dump($coil_id_arr);
        $this->assign('coil_id_arr', $coil_id_arr);
        $this->assign('coilarray', json_encode($coil_id_arr, true));
        $coil_id_arr_da = Db::name('coil')
            ->column('coilno', 'id');
//        $this->assign('coil_id_arr_da', $coil_id_arr_da);
        $this->assign('coil_id_arr_da1', json_encode($coil_id_arr_da));


//        $this->assign('coil_id_arr1', json_encode($coil_id_arr));
        $steel_grade_arr_da = Db::name('steel_grade')
            ->column('name', 'id');
//        var_dump($steel_grade_arr_da);
        $steel_grade_arr_da[0] = '';
        $this->assign('steel_grade_arr_da', $steel_grade_arr_da);
        $this->assign('steel_grade_arr_da1', json_encode($steel_grade_arr_da));
        $ht_id_arr = Db::query('select id,ht_number from cmf_ht where delete_time =0');
        $this->assign('ht_id_arr', $ht_id_arr);
        $this->assign('ht_id_arr1', json_encode($ht_id_arr));
        $this->assign('steel_grade_arr_da1', json_encode($steel_grade_arr_da));
        $this->assign('steel_grade_id_arr1', json_encode($steel_grade_id_arr));
        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '新增',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '新增',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function add()
    {
        $company_id_arr = Db::query('select id,name,abb_name from cmf_company where delete_time =0');
//        var_dump($company_id_arr);
        $this->assign('company_id_arr', $company_id_arr);

        $today = date('ymd', time());
        $name = '';
//        $this->success('ok', '',$today);
        $newnum = Db::name('plan_num')->where('today', $today)->order('id desc')->find();
        if ($newnum) {
            Db::name('plan_num')->insertGetId(array('today' => $today, 'order_num' => $newnum['order_num'] + 1, 'addtime' => time(),
                'admin_id' => cmf_get_current_admin_id()));
            $dd = str_pad($newnum['order_num'] + 1, 5, '0', STR_PAD_LEFT);
            $name = 'K' . $today . $dd;

        } else {
            Db::name('plan_num')->insertGetId(array('today' => $today, 'order_num' => 1, 'addtime' => time(),
                'admin_id' => cmf_get_current_admin_id()));
            $dd = str_pad(1, 5, '0', STR_PAD_LEFT);

            $name = 'K' . $today . $dd;
        }
        $this->assign('name', $name);
        $now_time = date('Y-m-d H:i', time());
        $this->assign('now_time', $now_time);
        $type_id_arr = array(
            0 => array('id' => 1, 'name' => '开平'),
            1 => array('id' => 2, 'name' => '切割'),
            2 => array('id' => 3, 'name' => '热处理'),
            3 => array('id' => 4, 'name' => '后处理'),
        );
        $c_type_arr = array(
            0 => array('id' => 1, 'name' => '内贸'),
            1 => array('id' => 2, 'name' => '调试'),
            2 => array('id' => 3, 'name' => '委外加工'),
            3 => array('id' => 4, 'name' => '外贸'),
        );
        $this->assign('c_type_arr', $c_type_arr);
        $this->assign('type_id_arr', $type_id_arr);
        $companytypea_arr = array(0 => array('id' => 1, 'name' => '自主'), 1 => array('id' => 2, 'name' => '来料'), 2 => array('id' => 3, 'name' => '委外'));
        $this->assign('companytypea_arr', $companytypea_arr);

        $steel_grade_id_arr = Db::query('select id,name from cmf_steel_grade where delete_time =0');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);

        $grade_id_arr = Db::query('select id,g_name from cmf_grade where delete_time =0');
        $this->assign('grade_id_arr', $grade_id_arr);

        $coil_id_arr = Db::query('select * from cmf_coil where delete_time =0');
//        var_dump($coil_id_arr);
        $this->assign('coil_id_arr', $coil_id_arr);

//        $this->assign('coil_id_arr1', json_encode($coil_id_arr));
        $steel_grade_arr_da = Db::name('steel_grade')
            ->column('name', 'id');
//        var_dump($steel_grade_arr_da);
        $steel_grade_arr_da[0] = '';
        $this->assign('steel_grade_arr_da', $steel_grade_arr_da);

        $ht_id_arr = Db::query('select id,ht_number from cmf_ht where delete_time =0');
        $this->assign('ht_id_arr', $ht_id_arr);

        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '新增提交',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '新增提交',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function addPost()
    {
        $params = array_map(function ($v) {
            return is_array($v) ? implode(',', $v) : $v;
        }, input('post.'));

        if (!$params) {
            $this->error('非法参数');
        }
//        if ($params['steel_grade_id'] == 0) {
//            $this->error('钢种号未选择');
//        }
        $params['delivery_time'] = strtotime($params['delivery_time']);
        $params['update_time'] = time();
        $params['pd'] = strtotime($params['pd']);
        $params['add_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();
        $params['user_id'] = cmf_get_current_admin_id();
//        Plan::create($params);
        $id = Db::name('plan')->insertGetId($params);
        $params['id'] = $id;
        if ($id) {
//            if ($params['sheets']) {
//                $co = (($params['d'] * ($params['w'] / 1000) * ($params['h'] / 1000) * 7.85) / 1000) * $params['sheets'];
//
//                Db::name('coil')->where()->update($params);
//            }
        }
        cmf_install_log($params, 'plan_log', 'add');
        $this->success('操作成功', 'xiafaindex');
    }

    public function editPostvue()
    {
        $params = input('post.formData');
        $plan = input('post.plan');

        if (!$params) {
            $this->error('非法参数');
        }
//        if ($params['steel_grade_id'] == 0) {
//            $this->error('钢种号未选择');
//        }

        $params['update_time'] = time();

//        $params['add_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();
        if ($params['delivery_time']) {
            $params['delivery_time'] = $params['delivery_time'] / 1000;
        }
        if ($params['pd']) {
            $params['pd'] = $params['pd'] / 1000;
        }
//        $params['user_id'] = cmf_get_current_admin_id();
        $params['coil_id'] = implode(',', $params['coil_id']);
//        var_dump($params);
//        exit();
//去除数组空元素
        $plan = array_filter($plan);

        if (count($plan) <= 0) {
            $this->error('非法参数');
        }

//        $this->success('操作成功', 'xiafaindex',$plan);
//        Plan::create($params);
        Db::name('plan')->startTrans();

        try {

            $in = Db::name('plan')->update($params);
            $id = $params['id'];
//            $params['id'] = $id;

            if ($in) {
                Db::name('preplate')->startTrans();
                $ids = array();
                try {
                    $newpalndid = Db::name('preplate')->where('plan_id', $id)->field('id')->where('delete_time', 0)->select();
                    foreach ($plan as $k => $v) {
                        foreach ($v as $key => $val) {
                            if (isset($val['weight'])){
                                $val['weight']=$val['weight']*1000;
                            }
                            if (isset($val['id'])) {

                                array_push($ids, $val['id']);
                                $val['update_time'] = time();

                                Db::name('preplate')->update($val);
                            } else {
                                $val['update_time'] = time();

                                $val['add_time'] = time();
                                $val['admin_id'] = cmf_get_current_admin_id();
//                    $val['user_id'] = cmf_get_current_admin_id();
                                unset($val['$isEdit']);
                                $val['coil_id'] = $k;
                                $val['plan_id'] = $id;
                                Db::name('preplate')->insertGetId($val);
                            }

                        }
                    }
                } catch (\Exception $e) {
                    // 回滚事务
                    Db::name('preplate')->rollback();
                    // 处理异常...
                }
//预设捆包入库
//$this->success('操作成功', 'xiafaindex');


                $arr = array();
                foreach ($newpalndid as $k => $v) {
                    array_push($arr, $v['id']);
                }
                $result1 = array_diff($arr, $ids);
                if (isset($result1)) {
                    foreach ($result1 as $key => $val) {
                        Db::name('preplate')->where('id', $val)->update(array('delete_time' => time()));
                    }
                }


            }
        } catch (\Exception $e) {
            // 回滚事务
            Db::name('plan')->rollback();
            // 处理异常...
        }
        cmf_install_log($params, 'plan_log', 'update');
        $this->success('操作成功', 'allindex');
    }

    public function addPostvue()
    {
        $params = input('post.formData');
        $plan = input('post.plan');

        if (!$params) {
            $this->error('非法参数');
        }
//        if ($params['steel_grade_id'] == 0) {
//            $this->error('钢种号未选择');
//        }

        $params['update_time'] = time();

        $params['add_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();
        if ($params['delivery_time']) {
            $params['delivery_time'] = $params['delivery_time'] / 1000;
        }
        if ($params['pd']) {
            $params['pd'] = $params['pd'] / 1000;
        }
        $params['user_id'] = cmf_get_current_admin_id();
        $params['coil_id'] = implode(',', $params['coil_id']);
//        var_dump($params);
//        exit();
//去除数组空元素
        $plan = array_filter($plan);

        if (count($plan) <= 0) {
            $this->error('非法参数');
        }

//        $this->success('操作成功', 'xiafaindex',$plan);
//        Plan::create($params);
        Db::name('plan')->startTrans();

        try {

            $id = Db::name('plan')->insertGetId($params);
            $params['id'] = $id;

            if ($id) {
                Db::name('preplate')->startTrans();
//            if ($params['sheets']) {
//                $co = (($params['d'] * ($params['w'] / 1000) * ($params['h'] / 1000) * 7.85) / 1000) * $params['sheets'];
//
//                Db::name('coil')->where()->update($params);
//            }
                try {

                    foreach ($plan as $k => $v) {
                        foreach ($v as $key => $val) {
                            if (isset($val['weight'])){
                                $val['weight']=$val['weight']*1000;
                            }

                            $val['update_time'] = time();
                            $val['update_time'] = time();
                            $val['add_time'] = time();
                            $val['admin_id'] = cmf_get_current_admin_id();
//                    $val['user_id'] = cmf_get_current_admin_id();
                            unset($val['$isEdit']);
                            $val['coil_id'] = $k;
                            $val['plan_id'] = $id;
//                            var_dump($val);
                            Db::name('preplate')->insertGetId($val);
                        }
                    }
                } catch (\Exception $e) {
                    var_dump($e->getMessage());
                    // 回滚事务
                    Db::name('preplate')->rollback();
                    // 处理异常...
                }
//预设捆包入库
//$this->success('操作成功', 'xiafaindex');
            }
        } catch (\Exception $e) {
//            var_dump($e->getMessage());
            // 回滚事务
            Db::name('plan')->rollback();
            // 处理异常...
        }
        cmf_install_log($params, 'plan_log', 'add');
        $this->success('操作成功', 'allindex');
    }

    /**
     * @adminMenu(
     *     'name'   => '修改',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '修改',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function edit()
    {
        $id = input('get.id/d');

        if (!is_numeric($id)) {
            $this->error('非法参数');
        }

        $res = Plan::where('id', $id)->find();

        $company_id_arr = Db::query('select id,name from cmf_company where delete_time =0');
//        var_dump($company_id_arr);
        $this->assign('company_id_arr', $company_id_arr);
        $type_id_arr = array(
            0 => array('id' => 1, 'name' => '开平'),
            1 => array('id' => 2, 'name' => '切割'),
            2 => array('id' => 3, 'name' => '热处理'),
            3 => array('id' => 4, 'name' => '后处理'),
        );
        $c_type_arr = array(
            0 => array('id' => 1, 'name' => '内贸'),
            1 => array('id' => 2, 'name' => '调试'),
            2 => array('id' => 3, 'name' => '委外加工'),
            3 => array('id' => 4, 'name' => '外贸'),
        );
        $this->assign('c_type_arr', $c_type_arr);
        $this->assign('type_id_arr', $type_id_arr);
        $companytypea_arr = array(0 => array('id' => 1, 'name' => '自主'), 1 => array('id' => 2, 'name' => '来料'), 2 => array('id' => 3, 'name' => '委外'));
        $this->assign('companytypea_arr', $companytypea_arr);

        $steel_grade_arr_da = Db::name('steel_grade')
            ->column('name', 'id');
        $steel_grade_arr_da[0] = '';
        $this->assign('steel_grade_arr_da', $steel_grade_arr_da);
        $this->assign('steel_grade_arr_da1', json_encode($steel_grade_arr_da));
        $steel_grade_id_arr = Db::query('select id,name from cmf_steel_grade where delete_time =0');
        $this->assign('steel_grade_id_arr', $steel_grade_id_arr);
        $grade_id_arr = Db::query('select id,g_name from cmf_grade where delete_time =0');
        $this->assign('grade_id_arr', $grade_id_arr);
        $coil_id_arr = Db::query('select * from cmf_coil where delete_time =0');
        $this->assign('coil_id_arr', $coil_id_arr);
        $ht_id_arr = Db::query('select id,ht_number from cmf_ht where delete_time =0');
        $this->assign('ht_id_arr', $ht_id_arr);
        $res['coil_id'] = explode(',', $res['coil_id']);

        return $this->fetch('', ['vo' => $res, 'domain' => request()->domain() . '/upload/']);
    }

    /**
     * @adminMenu(
     *     'name'   => '修改提交',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '修改提交',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function editPost()
    {
        $params = array_map(function ($v) {
            return is_array($v) ? implode(',', $v) : $v;
        }, input('post.'));

        if (!$params || empty($params['id'])) {
            $this->error('非法参数');
        }
        $params['delivery_time'] = strtotime($params['delivery_time']);
        $params['pd'] = strtotime($params['pd']);
        $params['update_time'] = time();
        $params['admin_id'] = cmf_get_current_admin_id();
        Plan::update($params);
        cmf_install_log($params, 'plan_log', 'update');
        $this->success('操作成功', 'xiafaindex');
    }

    /**
     * @adminMenu(
     *     'name'   => '删除',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除',
     *     'param'  => ''
     * )
     * @return mixed
     */
    public function del()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }

        Plan::where('id', $id)->update(array('delete_time' => time(), 'admin_id' => cmf_get_current_admin_id()));
        $params = Db::name('plan')->where('id', $id)->find();
        cmf_install_log($params, 'plan_log', 'del');
        $this->success('删除成功');
    }

    public function field()
    {
        $id = input('get.id/d');
        $field = input('get.field');

        if (!(is_numeric($id) && $id > 0 && $field)) {
            $this->error('非法参数');
        }

        $info = Plan::field($field)->where('id', $id)->find();
        $info[$field] = explode(',', $info[$field]);
        $list = [];
        foreach ($info[$field] as $k => $v) {
//            var_dump($v);
            $asset = Db::name('asset')->where('file_path', $v)->find();
            if ($asset) {
                $list[$k] = $asset;
            } else {
                if ($v != '') {
                    $list[$k]['filename'] = $v;
                    $list[$k]['file_path'] = $v;
                }
            }
        }
        $this->success('ok', '', $list);
    }

    /**
     * @adminMenu(
     *     'name'   => '接收计划',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '接收计划',
     *     'param'  => ''
     * )
     * 计划开始
     * @return void
     */
    public function jieshou()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }

        Plan::where('id', $id)->update(array('status' => 2));

        $this->success('接收成功');
    }


    public function jieshouover()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }

        Plan::where('id', $id)->update(array('status' => 3));

        $this->success('接收成功');
    }

    /**结束按钮
     *      *   @adminMenu(
     *     'name'   => '结束按钮',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '结束按钮',
     *     'param'  => ''
     * )
     * @return void
     */
    public function plateadds()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }
        $info = Plan::where('id', $id)->find();
        $infod = $info;
        $info = $info->toArray();
        $infod = $infod->toArray();
        $this->assign('infod', $infod);
        $info['coil_id'] = explode(',', $info['coil_id']);
        foreach ($info['coil_id'] as $k => $v) {
//            var_dump($v);
            $coilarray[$v] = Db::name('coil')->where('id', $v)->find();
        }
//        var_dump($coilarray);
        $this->assign('coilarray', json_encode($coilarray, true));
        $grade_id_arr = Db::query('select id,g_name from cmf_grade where delete_time =0');
        $this->assign('grade_id_arr', $grade_id_arr);
        $steel_id_arr = Db::query('select id,name from cmf_steel_grade where delete_time =0');
        $this->assign('steel_id_arr', $steel_id_arr);
        $coil_id_arr = Db::query('select id,coilno from cmf_coil where delete_time =0');

        $this->assign('coil_id_arr', $coil_id_arr);
        $ht_id_arr = Db::query('select id,ht_number,ht_name from cmf_ht where delete_time =0');
        $this->assign('ht_id_arr', $ht_id_arr);
        $coil_id_arr_da = Db::name('coil')
            ->column('coilno', 'id');
        $this->assign('coil_id_arr_da', $coil_id_arr_da);
        $this->assign('coil_id_arr_da1', json_encode($coil_id_arr_da));
//        var_dump($info);
        $this->assign('info', $info);


        $company_id_arr = Db::name('company')
            ->column('name', 'id');
        $this->assign('company_id_arr', json_encode($company_id_arr));
        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');
        $this->assign('ht_id_arr', json_encode($ht_id_arr));
        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');
        $this->assign('grade_id_arr', json_encode($grade_id_arr));
        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');
        $this->assign('steel_grade_id_arr', json_encode($steel_grade_id_arr));


        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    public function editvue()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }

        $this->assign('id', $id);
        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    public function plateaddsvue()
    {
        $id = input('get.id/d');

        if (!(is_numeric($id) && $id > 0)) {
            $this->error('非法参数');
        }

        $this->assign('id', $id);
        return $this->fetch('', ['domain' => request()->domain() . '/upload/']);
    }

    /**excel 导出
     *      *   @adminMenu(
     *     'name'   => 'excel导出',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '接收计划',
     *     'param'  => ''
     * )
     * @return void
     */
    public function outexcel()
    {
        //要导出的数据,二维
        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
        $lists = $lists->where('type', 1);
        $lists = $lists->paginate(['list_rows' => 10000, 'query' => [
            //'key_status' => $key_status
        ]]);

        $data = $lists->toArray();
        $data = $data['data'];


//类型
        $type = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $statusarr = array(1 => "已下发", 2 => "进行中", 3 => "已完成");
        $company_id_arr = Db::name('company')
            ->column('name', 'id');

        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');

        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');

        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');

        $plate_id_arr = Db::name('plate')
            ->column('name', 'id');
        $coil_id_arr_da = Db::name('coil')
            ->column('coilno', 'id');

        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');
        foreach ($data as $k => $vo) {
            $newdata[$k] = $vo;
            $newdata[$k]['add_time'] = date('Y-m-d H:i', $vo['add_time']);
            $newdata[$k]['update_time'] = date('Y-m-d H:i', $vo['update_time']);
            $newdata[$k]['delivery_time'] = date('Y-m-d H:i', $vo['delivery_time']);
            $newdata[$k]['pd'] = date('Y-m-d H:i', $vo['pd']);

            $newdata[$k]['type'] = $type[$vo['type']];
            $newdata[$k]['status'] = $statusarr[$vo['status']];
            $newdata[$k]['grade_id'] = isset($grade_id_arr[$vo['grade_id']]) ? $grade_id_arr[$vo['grade_id']] : '';
            $newdata[$k]['steel_grade_id'] = isset($steel_grade_id_arr[$vo['steel_grade_id']]) ? $steel_grade_id_arr[$vo['steel_grade_id']] : '';
            $newdata[$k]['coil_id'] = isset($coil_id_arr_da[$vo['coil_id']]) ? $coil_id_arr_da[$vo['coil_id']] : '';
            $newdata[$k]['ht_id'] = isset($ht_id_arr[$vo['ht_id']]) ? $ht_id_arr[$vo['ht_id']] : '';
            $newdata[$k]['company_id'] = isset($company_id_arr[$vo['company_id']]) ? $company_id_arr[$vo['company_id']] : '';
//            $newdata[$k]['parent_id'] = isset($plate_id_arr[$vo['parent_id']]) ? $plate_id_arr[$vo['parent_id']] : '';
            $newdata[$k]['admin_id'] = isset($user_arr[$vo['admin_id']]) ? $user_arr[$vo['admin_id']] : '';
            $newdata[$k]['user_id'] = isset($user_arr[$vo['user_id']]) ? $user_arr[$vo['user_id']] : '';
            $newdata[$k]['companytype'] = isset($companytypea_arr[$vo['companytype']]) ? $companytypea_arr[$vo['companytype']] : '';

        }


        $head = array('计划号',
            '归属类型',
            '状态',
            '计划类型',
            '合同编号',
            '客户名称',
            '牌号',
            '钢种',
            '交付时间',
            '生产日期',
            '钢卷信息',
            '厚',
            '宽',
            '长',
            '张数',
            '备注',
            '添加时间',
            '更新时间',
            '最后操作人',
            '创建人',
        );

        //数据中对应的字段，用于读取相应数据：
        $keys = [

            'name',
            'companytype',
            'status',
            'type',
            'ht_id',
            'company_id',
            'grade_id',
            'steel_grade_id',
            'delivery_time',
            'pd',
            'coil_id',
            'd',
            'w',
            'h',
            'sheets',
            'remrk',
            'add_time',
            'update_time',
            'admin_id',
            'user_id',
        ];


//        $head = array('id', 'name');//设置表头
//        $keys = ['id','name'];//数据中表头对应的字段，用于读取相应数据
//        var_dump($data);
        excel_out('计划导出' . date('ymdhis', time()), $newdata, $head, $keys);

    }

    /**excel 导出全部计划
     *      *   @adminMenu(
     *     'name'   => 'excel全部计划导出',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '接收计划',
     *     'param'  => ''
     * )
     * @return void
     */
    public function outexcel_all()
    {
        //要导出的数据,二维
        $lists = Plan::order('id desc');
//        if ($key_status) {
//            $lists = $lists->where('status', $key_status);
//        }
        $lists = $lists->where('delete_time', 0);
//        $lists = $lists->where('type', 1);
        $lists = $lists->paginate(['list_rows' => 10000, 'query' => [
            //'key_status' => $key_status
        ]]);

        $data = $lists->toArray();
        $data = $data['data'];


//类型
        $type = array(1 => '开平', 2 => '切割', 3 => '热处理', 4 => '后处理');
        $companytypea_arr = array(1 => '自主', 2 => '来料', 3 => '委外');
        $statusarr = array(1 => "已下发", 2 => "进行中", 3 => "已完成");
        $company_id_arr = Db::name('company')
            ->column('name', 'id');

        $ht_id_arr = Db::name('ht')
            ->column('ht_number', 'id');

        $grade_id_arr = Db::name('grade')
            ->column('g_name', 'id');

        $steel_grade_id_arr = Db::name('steel_grade')
            ->column('name', 'id');

        $plate_id_arr = Db::name('plate')
            ->column('name', 'id');
        $coil_id_arr_da = Db::name('coil')
            ->column('coilno', 'id');

        $user_arr = Db::name('user')
            ->column('user_nickname', 'id');
        foreach ($data as $k => $vo) {
            $newdata[$k] = $vo;
            $newdata[$k]['add_time'] = date('Y-m-d H:i', $vo['add_time']);
            $newdata[$k]['update_time'] = date('Y-m-d H:i', $vo['update_time']);
            $newdata[$k]['delivery_time'] = date('Y-m-d H:i', $vo['delivery_time']);
            $newdata[$k]['pd'] = date('Y-m-d H:i', $vo['pd']);

            $newdata[$k]['type'] = $type[$vo['type']];
            $newdata[$k]['status'] = $statusarr[$vo['status']];
            $newdata[$k]['grade_id'] = isset($grade_id_arr[$vo['grade_id']]) ? $grade_id_arr[$vo['grade_id']] : '';
            $newdata[$k]['steel_grade_id'] = isset($steel_grade_id_arr[$vo['steel_grade_id']]) ? $steel_grade_id_arr[$vo['steel_grade_id']] : '';
            $newdata[$k]['coil_id'] = isset($coil_id_arr_da[$vo['coil_id']]) ? $coil_id_arr_da[$vo['coil_id']] : '';
            $newdata[$k]['ht_id'] = isset($ht_id_arr[$vo['ht_id']]) ? $ht_id_arr[$vo['ht_id']] : '';
            $newdata[$k]['company_id'] = isset($company_id_arr[$vo['company_id']]) ? $company_id_arr[$vo['company_id']] : '';
//            $newdata[$k]['parent_id'] = isset($plate_id_arr[$vo['parent_id']]) ? $plate_id_arr[$vo['parent_id']] : '';
            $newdata[$k]['admin_id'] = isset($user_arr[$vo['admin_id']]) ? $user_arr[$vo['admin_id']] : '';
            $newdata[$k]['user_id'] = isset($user_arr[$vo['user_id']]) ? $user_arr[$vo['user_id']] : '';
            $newdata[$k]['companytype'] = isset($companytypea_arr[$vo['companytype']]) ? $companytypea_arr[$vo['companytype']] : '';

        }


        $head = array('计划号',
            '归属类型',
            '状态',
            '计划类型',
            '合同编号',
            '客户名称',
            '牌号',
            '钢种',
            '交付时间',
            '生产日期',
            '钢卷信息',
            '厚',
            '宽',
            '长',
            '张数',
            '备注',
            '添加时间',
            '更新时间',
            '最后操作人',
            '创建人',
        );

        //数据中对应的字段，用于读取相应数据：
        $keys = [

            'name',
            'companytype',
            'status',
            'type',
            'ht_id',
            'company_id',
            'grade_id',
            'steel_grade_id',
            'delivery_time',
            'pd',
            'coil_id',
            'd',
            'w',
            'h',
            'sheets',
            'remrk',
            'add_time',
            'update_time',
            'admin_id',
            'user_id',
        ];


//        $head = array('id', 'name');//设置表头
//        $keys = ['id','name'];//数据中表头对应的字段，用于读取相应数据
//        var_dump($data);
        excel_out('全部计划导出' . date('ymdhis', time()), $newdata, $head, $keys);

    }

    public function findid()
    {
        $coil = input('coil');
        $weight = 0;
        foreach ($coil as $k => $v) {
            $coildata = Db::name('coil')->where('id', $v)->field('weight')->find();
            $weight = $weight + $coildata['weight'];
        }
        return $weight;
    }
}